﻿#region Imports
using System;
using System.Drawing;
using System.Windows.Forms;
using CommonUtilities.Util;
#endregion

namespace CommonUtilities.Controls
{
    public class CUtil_InvisibleExitButton : Button
    {
        #region Properties
        protected readonly Form owner;
        public Form Owner { get { return owner; } }

        protected readonly Size size;
        public Size Size { get { return size; } }

        protected readonly Point loc;
        public Point Location { get { return loc; } }
        #endregion

        #region Constructors
        private CUtil_InvisibleExitButton()
            : base()
        {
            this.Click += new EventHandler(InvisibleExitButton_Click);

            base.Size = this.size = new Size(0, 0);
            base.Location = this.loc = new Point(5, 5);
        }

        public CUtil_InvisibleExitButton(Form owner)
            : this()
        {
            this.owner = owner;
            SetCancelButton(owner);
        }
        #endregion

        #region Events
        internal virtual void InvisibleExitButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            Owner.Close();
        }
        #endregion

        #region Methods
        public override string ToString()
        {
            return Utilities.ToString(this);
        }

        private void SetCancelButton(Form owner)
        {
            this.owner.CancelButton = this;
        }
        #endregion
    }
}
